<template>
  <div class="goods-tabs">
    <nav>
      <a
        :class="{ active: activeName === 'GoodsDetail' }"
        href="javascript:;"
        @click="clickTab('GoodsDetail')"
        >商品详情</a
      >
      <a
        :class="{ active: activeName === 'GoodsComment' }"
        href="javascript:;"
        @click="clickTab('GoodsComment')"
        >商品评价<span>({{ goods.commentCount }})</span></a
      >
    </nav>
    <!-- 切换内容的地方 -->
    <Component :is="tabs[activeName]" />
  </div>
</template>

<script setup lang="ts">
import GoodsDetail from './goods-detail.vue'
import GoodsComment from './goods-comment.vue'
import { PropType } from 'vue'
import { GoodsType } from '@/types/goods'

defineProps({
  goods: {
    type: Object as PropType<GoodsType>
  }
})
const activeName = ref('GoodsDetail')
const tabs: { [key: string]: any } = {
  GoodsDetail,
  GoodsComment
}
const clickTab = (name: string) => {
  activeName.value = name
}
</script>

<style scoped lang="scss">
.goods-tabs {
  min-height: 600px;
  background: #fff;
  nav {
    height: 70px;
    line-height: 70px;
    display: flex;
    border-bottom: 1px solid #f5f5f5;
    a {
      padding: 0 40px;
      font-size: 18px;
      position: relative;
      > span {
        color: $priceColor;
        font-size: 16px;
        margin-top: 10px;
      }
      &:first-child {
        border-right: 1px solid #f5f5f5;
      }
      &.active {
        &::before {
          content: '';
          position: absolute;
          left: 40px;
          bottom: -1px;
          width: 72px;
          height: 2px;
          background: $rbtColor;
        }
      }
    }
  }
}
</style>
